// pages/earn_pasture/earn_pasture.js
var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    box_bg_true:false,
    aaaaaa:'',
    bbbbbb:'',
    cooperate_points_list: [
      {
        id: '56',
        member_id: '6',
        member_name:'shike',
        p_member_id: '6',
        points: '0',
        create_time:'1970 - 01 - 01 08: 33: 40',
        num: '2',
        type: 'cooperate',
        avatar: 'http://192.168.0.120/upload/data/upload/shop/common/default_user_portrait.gif'
      },
      {
        id: '55',
        member_id: '6',
        member_name: 'shike',
        p_member_id: '6',
        points: '0',
        create_time: '1970 - 01 - 01 08: 33: 40',
        num: '2',
        type: 'cooperate',
        avatar: 'http://192.168.0.120/upload/data/upload/shop/common/default_user_portrait.gif'
      },
      {
        id: '54',
        member_id: '6',
        member_name: 'shike',
        p_member_id: '6',
        points: '0',
        create_time: '1970 - 01 - 01 08: 33: 40',
        num: '2',
        type: 'cooperate',
        avatar: 'http://192.168.0.120/upload/data/upload/shop/common/default_user_portrait.gif'
      },
      {
        id: '53',
        member_id: '6',
        member_name: 'shike',
        p_member_id: '6',
        points: '0',
        create_time: '1970 - 01 - 01 08: 33: 40',
        num: '2',
        type: 'cooperate',
        avatar: 'http://192.168.0.120/upload/data/upload/shop/common/default_user_portrait.gif'
      }

    ],
    cooperate_points_info:[],
    points_add_point:'',
    my_uid: '',
    share_bimg: {}
  },
  box_bg_hide(){
    this.setData({
      box_bg_true: false
    })
  },
  box_bg_show() {
    this.setData({
      box_bg_true: true
    })
  },
  //index.php?act=cooperate_points&op=signin_list
  add_cooperate_points_list(){
    let that = this; 
    let k = wx.getStorageSync('key');

    wx.request({
      url: ApiUrl + '/index.php?act=cooperate_points&op=signin_list',
      data: {
        key:k,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
        console.log('邀请好友瓜分积分-邀请列表:==>', result);
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            let res = result.data.datas.signin_list;
            console.log('邀请好友瓜分积分-邀请列表:==>', res);
            that.setData({
              // cooperate_points_list: res
            })
          }
        }
      }
    });
  },
  //index.php?act=cooperate_points&op=task_info
  cooperate_points_info(){
    let that = this;
    let k = wx.getStorageSync('key');
    wx.request({
      url: ApiUrl + '/index.php?act=cooperate_points&op=task_info',
      data: {
        key: k
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (result) {
        console.log('邀请好友瓜分积分-当前任务进度:==>', result);
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            let res = result.data.datas;
            console.log('邀请好友瓜分积分-当前任务进度:==>', res);
            that.setData({
              cooperate_points_info: res
            })
          }
        }
      }
    });
  },
  //index.php?act=cooperate_points&op=points_add
  points_add_(){
    let that = this;
    let k = wx.getStorageSync('key');
    let fid = wx.getStorageSync('fid');
    wx.request({
      url: ApiUrl + '/index.php?act=cooperate_points&op=points_add',
      data: {
        key: k,
        uid: fid
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
        console.log('邀请好友瓜分积分-点击邀请链接:==>', result);
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            let res = result.data.datas;
            console.log('邀请好友瓜分积分-点击邀请链接:==>', res);
            that.cooperate_points_info();
            that.setData({
              points_add_point: res,
              my_uid: false,
              aaaaaa:k,
              bbbbbb: fid
            })
          }
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    if (options.uid){
      that.points_add_();
      wx.setStorageSync('fid', options.uid);
      // that.setData({
      //   my_uid: true
      // })
    }
    this.add_cooperate_points_list();
    this.cooperate_points_info();
    this.share_bimg();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  //index.php?act=other&op=share_bimg
  //背景图设置
  share_bimg() {
    let that = this;
    wx.request({
      url: ApiUrl + '/index.php?act=other&op=share_bimg',
      data: {
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (result) {
        console.log('背景图设置:==>', result);
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            let res = result.data.datas;
            console.log('背景图设置:==>', res);
            that.setData({
              share_bimg: res
            })
          }
        }
      }
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (ops) {
    let uid = wx.getStorageSync('userId');
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      title: '天天分牧草，直接当钱花',
      imageUrl: '/image/WechatIMG91.jpeg',//图片地址
      path: '/pages/earn_pasture/earn_pasture?uid=' + uid,// 用户点击首先进入的当前页面
      success: function (res) {
        // 转发成功
        console.log("转发成功:");
        alert(1);
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:");
      }
    }
  }
})